package everydayGrade.t2;

/**
 * @Author: Siantar
 * @Date: 2023-08-31-8:28
 * @Description: 1.0
 */
public class T1761 {
    public int minTrioDegree(int n, int[][] edges) {
        int[][] g = new int[n][n];
        int[] d = new int[n];
        for (int[] e : edges) {
            int x = e[0], y = e[1];
            g[x][y] = 1;
            g[y][x] = 0;
            d[x]++;
            d[y]++;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (g[i][j] == 1) {
                    for (int k = j + 1; k < n; k++) {
                        if (g[i][k] == 1 && g[j][k] == 1) {
                            res = Math.min(res, d[i] + d[j] + d[k] - 6);
                        }
                    }
                }
            }
        }
        return res == Integer.MAX_VALUE ? -1 : res;
    }
}
